#!/usr/bin/env python
# encoding: utf-8
"""
#-------------------------------------------------------------------#
#                   CONFIDENTIAL --- CUSTOM STUDIOS                 #     
#-------------------------------------------------------------------#
#                                                                   #
#                   @Project Name : Globallawonline                #
#                                                                   #
#                   @File Name    : copyfile.py                      #
#                                                                   #
#                   @Programmer   : 李建                            #
#                                                                   #  
#                   @Start Date   : 2021/6/22 11:37                 #
#                                                                   #
#                   @Last Update  : 2021/6/22 15:21                 #
#                                                                   #
#-------------------------------------------------------------------#
# Classes:导出至2012-5底为止所有未翻译的pdf                              #
#                                                                   #
#-------------------------------------------------------------------#
"""
import os
import shutil


if __name__ == '__main__':
    path = input("请输入文件路径:")
    root_path = os.path.join(path)
    path = input("请输出路径:")
    out_path = os.path.join(path)
    path = input("请输入文件:")
    filel_path = os.path.join(path)
    r = open(filel_path)
    lines = r.readlines()
    file_list = []
    for line in lines:
        file_list.append(line.rstrip(' \n'))
    for root, dirs, files in os.walk(root_path, topdown=False):
        file_root_path = root.lstrip(root_path)
        for file in files:
            if file.__contains__('.pdf'):
                file_path = os.path.join(file_root_path, file)
                if file_path not in file_list:
                    target_path = os.path.join(out_path, file_path)
                    oringal_path = os.path.join(root, file)
                    pdf_traget_dir = os.path.dirname(target_path)
                    if not os.path.exists(pdf_traget_dir):
                        os.makedirs(pdf_traget_dir)
                    try:
                        shutil.copyfile(oringal_path, target_path)
                    except Exception as e:
                        with open("copyerro.txt", "a", encoding='utf-8') as f:
                            f.write(oringal_path + '\n')
                        print("文件复制出错:%s(%s)" % (oringal_path, str(e)))